package com.shizhanzhe.zxbapp.team;

import android.app.Activity;
import android.content.ClipboardManager;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.JsonObject;
import com.gyf.barlibrary.ImmersionBar;
import com.shizhanzhe.zxbapp.R;
import com.shizhanzhe.zxbapp.bean.UserBean;
import com.shizhanzhe.zxbapp.url.Path;
import com.shizhanzhe.zxbapp.utils.OkHttpDownloadJsonUtil;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by zz9527 on 2019/1/16.
 */
public class LeaderActivity extends Activity {
    private ClipboardManager cm;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_leader);
        ImmersionBar.with(this).statusBarColor(R.color.them)
                .fitsSystemWindows(true).init();
        final TextView one = findViewById(R.id.one);
        final TextView two = findViewById(R.id.two);
        final LinearLayout ll = findViewById(R.id.ll2);
        one.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                Toast.makeText(LeaderActivity.this, "复制成功", Toast.LENGTH_SHORT).show();
                cm.setText(one.getText().toString());
            }
        });
        two.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                Toast.makeText(LeaderActivity.this, "复制成功", Toast.LENGTH_SHORT).show();
                cm.setText(two.getText().toString());
            }
        });
        OkHttpDownloadJsonUtil.downloadJson(this, Path.LEADER(UserBean.uid), new OkHttpDownloadJsonUtil.onOkHttpDownloadListener() {
            @Override
            public void onsendJson(String json) {
                try {
                    JSONObject object = new JSONObject(json);
                    String one1 = object.optString("one");
                    String two1 = object.optString("two");
                    if (!"".equals(one1)) {
                        one.setText(one1);
                    }
                    if (!"".equals(two1)) {
                        two.setText(two1);
                        ll.setVisibility(View.VISIBLE);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ImmersionBar.with(this).destroy();
    }
}
